package com.zoffy.wmsbackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zoffy.wmsbackend.common.BaseResponse;
import com.zoffy.wmsbackend.common.CommonObj;
import com.zoffy.wmsbackend.common.ResultUtils;
import com.zoffy.wmsbackend.model.dto.stockin.StockInOrderDto;
import com.zoffy.wmsbackend.model.dto.stockin.StockInDTO;
import com.zoffy.wmsbackend.model.vo.stock.stockIn.StockInOrderDetailsVo;
import com.zoffy.wmsbackend.model.vo.stock.stockIn.StockInOrderVo;
import com.zoffy.wmsbackend.service.StockInOrderService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@PreAuthorize("hasAuthority('admin')")
@RequestMapping("/stockIn")
public class StockInController {
    @Resource
    private StockInOrderService stockInOrderService;
    @PostMapping("/import")
    public BaseResponse<Boolean> importStockIn(@RequestParam("file") MultipartFile file) throws IOException {
        Boolean res = stockInOrderService.importStockIn(file);
        return ResultUtils.success(res);
    }
    @PostMapping("/add")
    public BaseResponse<Boolean> addStock(@RequestBody StockInDTO stockDto){
        Boolean res = stockInOrderService.stockIn(stockDto);
        return ResultUtils.success(res);
    }
    @PostMapping("/list")
    public BaseResponse<Page<StockInOrderVo>> listByPage(@RequestBody com.zoffy.wmsbackend.common.RequestParam<StockInOrderDto> requestParam){
        Page<StockInOrderVo> res = stockInOrderService.listStockInOrderVoByPage(requestParam);
        return ResultUtils.success(res);
    }
    @PostMapping("/approval")
    public BaseResponse<Boolean> approval(@RequestBody CommonObj<Long> stockInId){
        Long id = stockInId.getData();
        boolean res = stockInOrderService.approval(id);
        return ResultUtils.success(res);
    }
    @GetMapping("/")
    public BaseResponse<StockInOrderDetailsVo> getDetailsById(@RequestParam("id") Long id){
        StockInOrderDetailsVo res = stockInOrderService.getDetailsById(id);
        return ResultUtils.success(res);
    }
}
